{extend name="common/adminBase" /}
{block name="body"}
<style>
  .layui-input-inline{
    width: 700px !important;
  }
  .layui-form-label{
    width:150px;
  }
  .date{
    width:280px; display: inline-block;
  }
  #uploadimg{
    position: absolute;
    top:155px;left:1060px;
  }
  .layui-upload-img {
    width: 92px;
    height: 92px;
  }
</style>
<body>
<div class="layui-fluid" style="background:#fff;">
  <div class="layui-row">
    <form class="layui-form">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>负责人信息</legend>
        </fieldset>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
              <span class="x-red">*</span>姓名
            </label>
            <div class="layui-input-inline">
              <input type="text"  name="fname" placeholder="请输入学校名称"  required="" lay-verify="required"
                     autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
              <span class="x-red">*</span>电话
            </label>
            <div class="layui-input-inline">
              <input type="text"  name="fphone" placeholder="请输入电话"  required="" lay-verify="required"
                     autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
              <span class="x-red">*</span>邮箱
            </label>
            <div class="layui-input-inline">
              <input type="text"  name="femail" placeholder="请输入邮箱" required="" lay-verify="required"
                     autocomplete="off" class="layui-input">
        </div>
        </div>
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>学校信息</legend>
      </fieldset>

      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>学校名称
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="name" placeholder="请输入学校名称" value="{$cate.title}" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>

      
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>学校地址
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="address" placeholder="请输入学校地址" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>学校邮箱
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="email" placeholder="请输入邮箱" id="mail" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>在校学生人数
        </label>
        <div class="layui-input-inline">
          <input type="number"  name="teacher_num" placeholder="请输入在校学生人数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>专职心理教师人数
        </label>
        <div class="layui-input-inline">
          <input type="number"  name="zhuan_num" placeholder="请输入专职心理教师人数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>功能教室 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="layui-btn layui-btn-normal" onclick="add()">添加</button> </legend>
      </fieldset>
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>个体辅导室
          <input type="hidden" name="gongnengname[]" value="个体辅导室" />
        </label>
        <div class="layui-input-inline" style="width:280px !important;">
            <input type="number" style="width:200px;" name="gongnengnum[]" value="" placeholder="请输入个数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
          
        </div>
        <div class="layui-input-inline" style="width:280px !important;">
          <input type="number"  style="width:200px;"  name="gongneng[]" placeholder="请输入平米数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>团体辅导室
          <input type="hidden" name="gongnengname[]" value="团体辅导室" />
        </label>
        <div class="layui-input-inline" style="width:280px !important;">
            <input type="number" style="width:200px;" name="gongnengnum[]" value="" placeholder="请输入个数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
          
        </div>
        <div class="layui-input-inline" style="width:280px !important;">
          <input type="number"  name="gongneng[]" style="width:200px;" placeholder="请输入平米数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>办公室接待区
          <input type="hidden" name="gongnengname[]" value="办公室接待区" />
        </label>
        <div class="layui-input-inline" style="width:280px !important;">
            <input type="number" style="width:200px;" name="gongnengnum[]" value="" placeholder="请输入个数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
          
        </div>
        <div class="layui-input-inline" style="width:280px !important;">
          <input type="number" style="width:200px;" name="gongneng[]" placeholder="请输入平米数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>
      <div id="add_html"></div>

      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>开设心理课程信息 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="layui-btn layui-btn-normal" onclick="add1()">添加</button></legend>
      </fieldset>
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>心理课程名称
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="class_name[]" placeholder="请输入心理课程名称" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>周学时
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="class_time[]"  placeholder="请输课时" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>年级
        </label>
        <div class="layui-input-inline">
            <select name="class_type[]" xm-select="select2">
                <option value="">---请选择---</option>
                <option value="小学一年级-小学六年级" >小学一年级-小学六年级</option>
                <option value="初中一年级-四年级" >初中一年级-四年级</option>
                <option value="高中一年级-高中三年级"  >高中一年级-高中三年级</option>
                <option value="中职一年级-中职三年级" >中职一年级-中职三年级</option>
            </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>主讲教师
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="class_teacher[]" placeholder="请输入主讲教师" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>课程介绍
        </label>
        <div class="layui-input-inline">
          <textarea name="class_info[]" class="layui-textarea"></textarea>
        </div>
      </div>
      <div id="add_html2"></div>
      <!--<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">-->
      <!--  <legend>专职老师信息 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="layui-btn layui-btn-normal" onclick="add2()">添加</button></legend>-->
      <!--</fieldset>-->
      <!--<div class="layui-form-item">-->
      <!--  <label for="username" class="layui-form-label">-->
      <!--    <span class="x-red">*</span>姓名-->
      <!--  </label>-->
      <!--  <div class="layui-input-inline">-->
      <!--    <input type="text"  name="teacher_name[]" placeholder="请输入姓名" required="" lay-verify="required"-->
      <!--           autocomplete="off" class="layui-input">-->
      <!--  </div>-->
      <!--</div>-->
      <!--<div class="layui-form-item">-->
      <!--  <label for="username" class="layui-form-label">-->
      <!--    <span class="x-red">*</span>性别-->
      <!--  </label>-->
      <!--  <div class="layui-input-inline">-->
      <!--    <select name="teacher_sex[]">-->
      <!--      <option value="">选择性别</option>-->
      <!--      <option value="男">男</option>-->
      <!--      <option value="女">女</option>-->
      <!--    </select>-->
      <!--  </div>-->
      <!--</div>-->
      <!--<div class="layui-form-item">-->
      <!--  <label for="username" class="layui-form-label">-->
      <!--    <span class="x-red">*</span>年龄-->
      <!--  </label>-->
      <!--  <div class="layui-input-inline">-->
      <!--    <input type="num"  name="teacher_year[]" placeholder="请输入年龄" required="" lay-verify="required"-->
      <!--           autocomplete="off" class="layui-input">-->
      <!--  </div>-->
      <!--</div>-->
      <!--<div class="layui-form-item">-->
      <!--  <label for="username" class="layui-form-label">-->
      <!--    <span class="x-red">*</span>工作年限-->
      <!--  </label>-->
      <!--  <div class="layui-input-inline">-->
      <!--    <input name="work_stime[]" placeholder="开始时间" autocomplete="off"  class="layui-input date"/> 至 <input name="work_etime[]" placeholder="截止时间" autocomplete="off"  class="layui-input date"/>-->
      <!--  </div>-->
      <!--</div>-->
      <!--<div class="layui-form-item">-->
      <!--  <label for="username" class="layui-form-label">-->
      <!--    <span class="x-red">*</span>证书等级-->
      <!--  </label>-->
      <!--  <div class="layui-input-inline">-->
      <!--    <select name="teacher_zhizheng[]">-->
      <!--      <option value="">请选择</option>-->
      <!--      <option value="A证">A证</option>-->
      <!--      <option value="B证">B证</option>-->
      <!--      <option value="C证">C证</option>-->
      <!--      <option value="其他">其他</option>-->
      <!--      <option value="无">无</option>-->
      <!--    </select>-->
      <!--  </div>-->
      <!--</div>-->
      <!--<div class="layui-form-item">-->
      <!--  <label for="username" class="layui-form-label">-->
      <!--    <span class="x-red">*</span>资料上传-->
      <!--  </label>-->
      <!--  <div class="layui-input-inline">-->
      <!--    <button type="button" class="layui-btn upload" id="1"><i class="layui-icon"></i>上传文件</button>-->
      <!--    <input type="hidden" name="teach_field[]" id="field_1" />-->
      <!--  </div>-->
      <!--</div>-->
      <div id="teacher"></div>
      <div class="layui-form-item">
        <label for="L_repass" class="layui-form-label">
        </label>
        <button  class="layui-btn" lay-filter="add" lay-submit="">
          保存
        </button>

      </div>
    </form>
  </div>
</div>
<script>
 layui.config({
                base: '/static/xadmin/js/' //此处路径请自行处理, 可以使用绝对路径
            }).extend({
                formSelects: 'formSelects-v4'
            });
layui.use(['form', 'layer','laydate','upload','formSelects'],
        function() {
          $ = layui.jquery;
          var form = layui.form, layer = layui.layer;
          var laydate = layui.laydate;
          var upload = layui.upload;
            var formSelects = layui.formSelects;

          lay('.date').each(function () {
            laydate.render({
              elem: this, //元素
            });
          });
          lay('.upload').each(function () {
            upload.render({
              elem: this
              , url: '/index/index/uploadfield' //改成您自己的上传接口
              , accept: 'file' //普通文件
              // ,before:function(obj){
              //
              // }
              , done: function (res) {
                // console.log(this.item.attr('id'));
                $("#field_"+this.item.attr('id')).val(res.msg);
                layer.msg("上传成功");
              }
            });
          });
          //监听提交
          form.on('submit(add)', function(data) {

            //验证邮箱
            var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
            var myemail = $("#mail").val();
            if(!myReg.test(myemail)){
              layer.msg('邮箱格式不对!');
              return false;
            }
            //发异步，把数据提交给php
            $.ajax({
              url:"/index/index/renzhengsubmit",
              data:data.field,
              type:'post',
              dataType:'json',
              success:function (res) {
                if (res.status==1){
                  window.location.href = "/index/school/shenlist";
                }else{
                  layer.alert(res.msg,function (index) {
                    layer.close(index);
                  })
                }
              }
            })

            return false;
          });

        });
        var gongneng = 2;
        function add(){
          var html ='';
          gongneng+=1;
          html =  '<div id="gongneng_'+gongneng+'">'+
                  '<div class="layui-form-item">\n' +
                  '        <label for="username" class="layui-form-label">\n' +
                  '          <input type="text" style="position: relative;top:-10px;" class="layui-input" name="gongnengname['+gongneng+']" value="" />\n' +
                  '        </label>\n' +
                  '        <div class="layui-input-inline" style="width:280px !important;">\n' +
                  '          <input type="number" style="width:200px;" name="gongnengnum['+gongneng+']" placeholder="请输入个数" required="" lay-verify="required"\n' +
                  '                 autocomplete="off" style="width:350px;" class="layui-input"></div>'+
                  '        <div class="layui-input-inline" style="width:280px !important;">\n' +
                  '          <input type="number" style="width:200px;" name="gongneng['+gongneng+']" placeholder="请输入平米数" required="" lay-verify="required"\n' +
                  '                 autocomplete="off" style="width:350px;" class="layui-input"><button type="button" style="position: relative;top:-30px;left:400px;" class="layui-btn layui-btn-danger" onclick="lot('+gongneng+')">删除</button>\n' +
                  '        </div>\n' +
                  '      </div>'+
                  '</div>';
          $("#add_html").append(html);
        }
      function lot(n){
        $("#gongneng_"+n).remove();
      }
      var classinfo=0;
      function add1(){
        var html ='';
        classinfo+=1;
        html = '<div id="classinfo_'+classinfo+'">'+
                '<div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>心理课程名称\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <input type="text"  name="class_name['+classinfo+']" placeholder="请输入心理课程名称" required="" lay-verify="required"\n' +
                '                 autocomplete="off" class="layui-input">\n' +
                '        </div>\n' +
                '      </div>\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>课时\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <input type="text"  name="class_time['+classinfo+']" placeholder="请输课时" required="" lay-verify="required"\n' +
                '                 autocomplete="off" class="layui-input">\n' +
                '        </div>\n' +
                '      </div>\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>授课方式\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <input type="text"  name="class_type['+classinfo+']" placeholder="请输入授课方式" required="" lay-verify="required"\n' +
                '                 autocomplete="off" class="layui-input">\n' +
                '        </div>\n' +
                '      </div>\n' +
                '\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>主讲教师\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <input type="text"  name="class_teacher['+classinfo+']" placeholder="请输入主讲教师" required="" lay-verify="required"\n' +
                '                 autocomplete="off" class="layui-input">\n' +
                '        </div>\n' +
                '      </div>\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>课程介绍\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <textarea name="class_info['+classinfo+']" class="layui-textarea"></textarea>\n' +
                '        </div>\n<button type="button" style="position: relative;top:-10px;left:100px;" class="layui-btn layui-btn-danger" onclick="lot1('+classinfo+')">删除</button>' +
                '      </div></div>';
        $("#add_html2").append(html);
      }
  function lot1(n){
        // alert(123);
    $("#classinfo_"+n).remove();
  }
  var teacher = 1;
  function add2(){
        var html = '';
        teacher +=1;
        html =  '<div id="teacher_'+teacher+'">'+
                '<div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>姓名\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <input type="text"  name="teacher_name['+teacher+']" placeholder="请输入姓名" required="" lay-verify="required"\n' +
                '                 autocomplete="off" class="layui-input">\n' +
                '        </div>\n' +
                '      </div>\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>性别\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <select name="teacher_sex['+teacher+']">\n' +
                '            <option value="">选择性别</option>\n' +
                '            <option value="男">男</option>\n' +
                '            <option value="女">女</option>\n' +
                '          </select>\n' +
                '        </div>\n' +
                '      </div>\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>年龄\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <input type="num"  name="teacher_year['+teacher+']" placeholder="请输入年龄" required="" lay-verify="required"\n' +
                '                 autocomplete="off" class="layui-input">\n' +
                '        </div>\n' +
                '      </div>\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>工作年限\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <input name="work_stime['+teacher+']" placeholder="开始时间" autocomplete="off"  class="layui-input date"/> 至 <input name="work_etime['+teacher+']" placeholder="截止时间" autocomplete="off"  class="layui-input date"/>\n' +
                '        </div>\n' +
                '      </div>\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>证书登记\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <select name="teacher_zhizheng['+teacher+']">\n' +
                '            <option value="">请选择</option>\n' +
                '            <option value="A1证">A1证</option>\n' +
                '            <option value="A2证">A2证</option>\n' +
                '            <option value="B1证">B1证</option>\n' +
                '            <option value="B2证">B2证</option>\n' +
                '            <option value="C证">C证</option>\n' +
                '          </select>\n' +
                '        </div>\n' +
                '      </div>\n' +
                '      <div class="layui-form-item">\n' +
                '        <label for="username" class="layui-form-label">\n' +
                '          <span class="x-red">*</span>资料上传\n' +
                '        </label>\n' +
                '        <div class="layui-input-inline">\n' +
                '          <button type="button" class="layui-btn upload" id="'+teacher+'"><i class="layui-icon"></i>上传文件</button>\n' +
                '          <input type="hidden" name="teach_field['+teacher+']" id="field_'+teacher+'" />\n' +
                '        </div>\n<button type="button" style="position: relative;left:50px;" class="layui-btn layui-btn-danger" onclick="lot2('+teacher+')">删除</button>' +
                '      </div></div>';
    $("#teacher").append(html);
    layui.use(['laydate','form','upload'], function(){
      var laydate = layui.laydate;
      var upload = layui.upload;
      var form = layui.form;
      form.render();
      //对每个laydate
      lay('.date').each(function(){
        laydate.render({
          elem: this,
          trigger: 'click'
        });
      });
      lay('.upload').each(function () {
        upload.render({
          elem: this
          , url: '/index/index/uploadfield' //改成您自己的上传接口
          , accept: 'file' //普通文件
          , done: function (res) {
            $("#field_"+this.item.attr('id')).val(res.msg);
            layer.msg("上传成功");
          }
        });
      });
    });
  }

  function lot2(n){
    $("#teacher_"+n).remove();
  }
</script>
</body>

{/block}
